package com.yssoft.controller.app.equipment;

import com.yssoft.entity.core.TCode;
import com.yssoft.entity.equipment.TEquipmentP;
import com.yssoft.entity.equipment.TEquipmentT;
import com.yssoft.entity.inventory.TWarehouse;
import com.yssoft.service.equipment.EquipmentPService;
import com.yssoft.service.equipment.EquipmentTService;
import com.yssoft.service.inventory.WarehouseService;
import com.yssoft.utils.AppUtil;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @类名称: EquipmentPController
 * @类描述: 检验设备控制器
 * @作者: 于兴达
 * @创建时间:2018年9月7日 下午19:46:50
 */
@CrossOrigin//解决跨域session问题
@Controller
@RequestMapping("/app/equipmentt")
public class EquipmentTController {
    
    @Resource
    private EquipmentTService equipmentTService;
    
    /**
     * @方法名称: getWarehouseList
     * @功能描述: 获取检验设备列表
     * @作者: 于兴达
     * @创建时间:2018年9月7日 下午19:49:38
     * @param companyId 企业id
     * @param name 生产设备名
     * @return Object
     */
    @RequestMapping(value = "getEquipmentTList",method = RequestMethod.GET)
    @ResponseBody
    public Object getWarehouseList(int page, int limit,Integer companyId,String name) {
    	 if (null == companyId) {
             return AppUtil.returnMapJson("0", "查询失败，请传递企业id", null);
         } 
         try {
             List<Map<String, Object>> warehouseList = equipmentTService.findAll(page,limit,companyId,name);
             return AppUtil.returnListJson("1", "查询成功!", warehouseList);
         } catch (NumberFormatException e) {
             return AppUtil.returnMapJson("0", "查询失败!"+e.getMessage(), null);
         }
    }
    
    /**
     * @方法名称: getOne
     * @功能描述: 根据检验设备id查询生检验设备
     * @作者: 于兴达
     * @创建时间:2018年9月7日 下午19:50:38
     * @param id 仓库id
     * @return Object
     */
    @RequestMapping(value = "getOne",method = RequestMethod.GET)
    @ResponseBody
    public Object getOne(String id) {
         try {
             Map<String, Object> equipmentp = equipmentTService.getOne(id);
             return AppUtil.returnMapJson("1", "查询成功!", equipmentp);
         } catch (NumberFormatException e) {
             return AppUtil.returnMapJson("0", "查询失败!"+e.getMessage(), null);
         }
    }
    
    /**
     * @方法名称: saveEquipmentT
     * @功能描述: 保存检验设备
     * @作者: 于兴达
     * @创建时间:2018年9月7日 下午19:04:38
     * @param equipmentP 生产设备实体
     * @param id 生产线id
     * @return Object
     */
    @RequestMapping(value = "saveEquipmentT",method = RequestMethod.POST)
    @ResponseBody
    public Object saveEquipmentT(TEquipmentT equipmentT,  @RequestParam("files") MultipartFile[] files,HttpServletRequest request) {
         try {
        	 equipmentTService.saveEquipmentT(equipmentT,files, request);
             return AppUtil.returnMapJson("1", "保存成功!", null);
         } catch (NumberFormatException e) {
             return AppUtil.returnMapJson("0", "保存失败!"+e.getMessage(), null);
         }
    }
    /**
     * @方法名称: deleteEquipmentT
     * @功能描述: 删除检验设备
     * @作者: 于兴达
     * @创建时间:2018年9月7日 下午19:51:38
     * @param id 设备id
     * @return Object
     */
    @RequestMapping(value = "deleteEquipmentT",method = RequestMethod.POST)
    @ResponseBody
    public Object deleteEquipmentP(String id) {
         try {
        	 equipmentTService.deleteEquipmentT(id);
             return AppUtil.returnMapJson("1", "删除成功!", null);
         } catch (NumberFormatException e) {
             return AppUtil.returnMapJson("0", "删除失败!"+e.getMessage(), null);
         }
    }
    /**
     * @方法名称: deleteImg
     * @功能描述: 删除图片
     * @作者: 于兴达
     * @创建时间:2018年9月08日 上午11:35:38
     * @return Map<String, Object>
     */
	@RequestMapping(value = "deleteImg",method = RequestMethod.POST)
    @ResponseBody
    public Object deleteImg(String id) {
         try {
        	 equipmentTService.deleteImg(id);
             return AppUtil.returnMapJson("1", "删除成功!", null);
         } catch (NumberFormatException e) {
             return AppUtil.returnMapJson("0", "删除失败!"+e.getMessage(), null);
         }
    }
}
